class Solution:
    def toHex(self, num: int) -> str:
        if num == 0:
            return '0'
        
        hex_chars = '0123456789abcdef'
        res = ''

        num &= 0xffffffff

        while num > 0:
            res = hex_chars[num % 16] + res
            num //= 16
        return res
if __name__ == '__main__':
    s = Solution()
    print(s.toHex(26)) # "1a"
    print(s.toHex(-1)) # "ffffffff"
    print(s.toHex(0)) # "0"